home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Development Kits / MPW etc. / MPW-GM / Interfaces&Libraries / Interfaces / PInterfaces / fenv.p < prev    next >
Encoding:
Text File  |  1998-02-17  |  11.2 KB  |  276 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        fenv.p
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.1
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. }
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT fenv;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __FENV__}
  28. {$SETC __FENV__ := 1}
  29.  
  30. {$I+}
  31. {$SETC fenvIncludes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34. {$IFC UNDEFINED __CONDITIONALMACROS__}
  35. {$I ConditionalMacros.p}
  36. {$ENDC}
  37.  
  38.  
  39. {$PUSH}
  40. {$ALIGN MAC68K}
  41. {$LibExport+}
  42.  
  43. {$IFC TARGET_OS_MAC }
  44. {
  45.     A collection of functions designed to provide access to the floating
  46.     point environment for numerical programming. It is modeled after
  47.     the floating-point requirements in C9X.
  48.     
  49.     The file <fenv.h> declares many functions in support of numerical
  50.     programming.  It provides a set of environmental controls similar to
  51.     the ones found in <SANE.h>.  Programs that test flags or run under
  52.     non-default modes must do so under the effect of an enabling
  53.     "fenv_access" pragma.
  54. }
  55.  
  56. {*******************************************************************************
  57. *                                                                                *
  58. *    fenv_t         is a type for representing the entire floating-point        *
  59. *                     environment in a single object.                              *
  60. *                                                                                *
  61. *     fexcept_t        is a type for representing the floating-point                *
  62. *                     exception flag state collectively.                           *
  63. *                                                                                *
  64. *******************************************************************************}
  65. {$IFC TARGET_CPU_PPC }
  66.  
  67. TYPE
  68.     fenv_t                                = LONGINT;
  69.     fexcept_t                            = LONGINT;
  70. {    Definitions of floating-point exception macros                          }
  71.  
  72. CONST
  73.     FE_INEXACT                    = $02000000;
  74.     FE_DIVBYZERO                = $04000000;
  75.     FE_UNDERFLOW                = $08000000;
  76.     FE_OVERFLOW                    = $10000000;
  77.     FE_INVALID                    = $20000000;
  78.  
  79.  
  80. {    Definitions of rounding direction macros                                }
  81.     FE_TONEAREST                = $00000000;
  82.     FE_TOWARDZERO                = $00000001;
  83.     FE_UPWARD                    = $00000002;
  84.     FE_DOWNWARD                    = $00000003;
  85.  
  86. {$ENDC}
  87. {$IFC TARGET_CPU_68K }
  88. {$IFC TARGET_RT_MAC_68881 }
  89.  
  90. TYPE
  91.     fexcept_t                            = LONGINT;
  92.     fenv_tPtr = ^fenv_t;
  93.     fenv_t = RECORD
  94.         FPCR:                    LONGINT;
  95.         FPSR:                    LONGINT;
  96.     END;
  97.  
  98.  
  99. CONST
  100.     FE_INEXACT                    = $00000008;                    {  ((long)(8))    }
  101.     FE_DIVBYZERO                = $00000010;                    {  ((long)(16))   }
  102.     FE_UNDERFLOW                = $00000020;                    {  ((long)(32))   }
  103.     FE_OVERFLOW                    = $00000040;                    {  ((long)(64))   }
  104.     FE_INVALID                    = $00000080;                    {  ((long)(128))  }
  105.  
  106. {$ELSEC}
  107.  
  108. TYPE
  109.     fexcept_t                            = INTEGER;
  110.     fenv_t                                = INTEGER;
  111.  
  112. CONST
  113.     FE_INVALID                    = $0001;                        {  ((short)(1))   }
  114.     FE_UNDERFLOW                = $0002;                        {  ((short)(2))   }
  115.     FE_OVERFLOW                    = $0004;                        {  ((short)(4))   }
  116.     FE_DIVBYZERO                = $0008;                        {  ((short)(8))   }
  117.     FE_INEXACT                    = $0010;                        {  ((short)(16))  }
  118.  
  119. {$ENDC}
  120.     FE_TONEAREST                = $0000;                        {  ((short)(0))   }
  121.     FE_UPWARD                    = $0001;                        {  ((short)(1))   }
  122.     FE_DOWNWARD                    = $0002;                        {  ((short)(2))   }
  123.     FE_TOWARDZERO                = $0003;                        {  ((short)(3))   }
  124.  
  125. {    Definitions of rounding precision macros  (68K only)                    }
  126.     FE_LDBLPREC                    = $0000;                        {  ((short)(0))   }
  127.     FE_DBLPREC                    = $0001;                        {  ((short)(1))   }
  128.     FE_FLTPREC                    = $0002;                        {  ((short)(2))   }
  129.  
  130. {$ENDC}
  131. {    The bitwise OR of all exception macros                                  }
  132.  
  133. CONST
  134.     FE_ALL_EXCEPT = ( FE_INEXACT + FE_DIVBYZERO + FE_UNDERFLOW + FE_OVERFLOW + FE_INVALID );
  135.  
  136. {    Definition of pointer to IEEE default environment object               }
  137. VAR
  138.  {$PUSH}
  139.  {$J+}
  140.  _FE_DFL_ENV: fenv_t;               { default environment object        }
  141.  {$POP}
  142.  
  143. {******************************************************************************
  144. *     The following functions provide access to the exception flags.  The      *
  145. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  146. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  147. ******************************************************************************}
  148. {******************************************************************************
  149. *     The function "feclearexcept" clears the supported exceptions represented *
  150. *     by its argument.                                                         *
  151. ******************************************************************************}
  152. PROCEDURE feclearexcept(excepts: LONGINT); C;
  153.  
  154.  
  155. {******************************************************************************
  156. *    The function "fegetexcept" stores a representation of the exception       *
  157. *     flags indicated by the argument "excepts" through the pointer argument   *
  158. *     "flagp".                                                                 *
  159. ******************************************************************************}
  160. PROCEDURE fegetexcept(VAR flagp: fexcept_t; excepts: LONGINT); C;
  161.  
  162.  
  163. {******************************************************************************
  164. *     The function "feraiseexcept" raises the supported exceptions             *
  165. *     represented by its argument.                                             *
  166. ******************************************************************************}
  167. PROCEDURE feraiseexcept(excepts: LONGINT); C;
  168.  
  169.  
  170. {******************************************************************************
  171. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  172. *     by the int argument "excepts" according to the representation in the     *
  173. *     object pointed to by the pointer argument "flagp".  The value of         *
  174. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  175. *     This function does not raise exceptions; it just sets the state of       *
  176. *     the flags.                                                               *
  177. ******************************************************************************}
  178. PROCEDURE fesetexcept({CONST}VAR flagp: fexcept_t; excepts: LONGINT); C;
  179.  
  180.  
  181. {******************************************************************************
  182. *     The function "fetestexcept" determines which of the specified subset of  *
  183. *     the exception flags are currently set.  The argument "excepts" specifies *
  184. *     the exception flags to be queried as a bitwise OR of the exception       *
  185. *     macros.  This function returns the bitwise OR of the exception macros    *
  186. *     corresponding to the currently set exceptions included in "excepts".     *
  187. ******************************************************************************}
  188. FUNCTION fetestexcept(excepts: LONGINT): LONGINT; C;
  189.  
  190.  
  191. {******************************************************************************
  192. *     The following functions provide control of rounding direction modes.     *
  193. ******************************************************************************}
  194. {******************************************************************************
  195. *     The function "fegetround" returns the value of the rounding direction    *
  196. *     macro which represents the current rounding direction.                   *
  197. ******************************************************************************}
  198. FUNCTION fegetround: LONGINT; C;
  199.  
  200.  
  201. {******************************************************************************
  202. *     The function "fesetround" establishes the rounding direction represented *
  203. *     by its argument.  It returns nonzero if and only if the argument matches *
  204. *     a rounding direction macro.  If not, the rounding direction is not       *
  205. *     changed.                                                                 *
  206. ******************************************************************************}
  207. FUNCTION fesetround(round: LONGINT): LONGINT; C;
  208.  
  209.  
  210. {******************************************************************************
  211. *    The following functions manage the floating-point environment, exception  *
  212. *    flags and dynamic modes, as one entity.                                   *
  213. ******************************************************************************}
  214. {******************************************************************************
  215. *     The function "fegetenv" stores the current floating-point environment    *
  216. *     in the object pointed to by its pointer argument "envp".                 *
  217. ******************************************************************************}
  218. PROCEDURE fegetenv(VAR envp: fenv_t); C;
  219.  
  220.  
  221. {******************************************************************************
  222. *     The function "feholdexcept" saves the current environment in the object  *
  223. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  224. *     and clears floating-point exception enables.  This function supersedes   *
  225. *     the SANE function "procentry", but it does not change the current        *
  226. *     rounding direction mode.                                                 *
  227. ******************************************************************************}
  228. FUNCTION feholdexcept(VAR envp: fenv_t): LONGINT; C;
  229.  
  230.  
  231. {******************************************************************************
  232. *     The function "fesetenv" installs the floating-point environment          *
  233. *     environment represented by the object pointed to by its argument         *
  234. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  235. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  236. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  237. ******************************************************************************}
  238. PROCEDURE fesetenv({CONST}VAR envp: fenv_t); C;
  239.  
  240.  
  241. {******************************************************************************
  242. *     The function "feupdateenv" saves the current exceptions into its         *
  243. *     automatic storage, installs the environment represented through its      *
  244. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  245. *     This function, which supersedes the SANE function "procexit", can be     *
  246. *     used in conjunction with "feholdexcept" to write routines which hide     *
  247. *     spurious exceptions from their callers.                                  *
  248. ******************************************************************************}
  249. PROCEDURE feupdateenv({CONST}VAR envp: fenv_t); C;
  250.  
  251.  
  252. {$IFC TARGET_CPU_68K }
  253. {******************************************************************************
  254. *     The following functions provide control of rounding precision.           *
  255. *     Because the PowerPC does not provide this capability, these functions    *  
  256. *     are available only for the 68K Macintosh.  Rounding precision values     *
  257. *     are defined by the rounding precision macros.  These functions are       *
  258. *     equivalent to the SANE functions getprecision and setprecision.          *
  259. ******************************************************************************}
  260. FUNCTION fegetprec: LONGINT; C;
  261. FUNCTION fesetprec(precision: LONGINT): LONGINT; C;
  262. {$ENDC}
  263. {$ENDC}  {TARGET_OS_MAC}
  264.  
  265.  
  266. {$ALIGN RESET}
  267. {$POP}
  268.  
  269. {$SETC UsingIncludes := fenvIncludes}
  270.  
  271. {$ENDC} {__FENV__}
  272.  
  273. {$IFC NOT UsingIncludes}
  274.  END.
  275. {$ENDC}
  276.